#include "GUILoadMapDialog.h"

#include <QGridLayout>
#include <QPushButton>
#include <QLabel>
#include <QFileInfoList>
#include <QFileInfo>


//FIXME: deze laadt nu alle namen in die in de map staan. mss enkel die bestanden toelaten met een xml extensie
GUILoadMapDialog::GUILoadMapDialog(QWidget* parent, Qt::WFlags f)
	: QDialog(parent, f), dir("resources/maps")
{
 	if (!dir.exists())
         qWarning("Kan geen maps vinden");

	setModal(true);
	QGridLayout* layout = new QGridLayout(this);
	this->setLayout( layout );	

	QPushButton* cancelButton = new QPushButton(tr("&Annuleer"), this);
	QObject::connect( cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
	layout->addWidget(cancelButton, 2, 0, 1, 1);
	QPushButton* okButton = new QPushButton(tr("&Ok"), this);
	QObject::connect( okButton, SIGNAL(clicked()), this, SLOT(accept()));
	layout->addWidget(okButton, 2, 1, 1, 1);

   	dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting( QDir::Name );

	m_list = new QListWidget(this);

    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) {
         QFileInfo fileInfo = list.at(i);
         
		new QListWidgetItem(fileInfo.baseName(), m_list);
		m_list->setCurrentRow(0);
    }
	layout->addWidget(m_list, 0, 0, 2, 2);
	m_map = "";
}

void GUILoadMapDialog::accept()
{
	m_map = m_list->currentItem()->text();	
	QDialog::accept();
}
